/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
    public:
        TreeNode* pruneTree(TreeNode* root) 
        {
            TreeNode* left = root->left == nullptr ? nullptr : pruneTree(root->left);    
            TreeNode* right = root->right == nullptr ? nullptr : pruneTree(root->right);    
    
            if (!left)
            {
                delete root->left;
                root->left = left;
            }
            if(!right)
            {
                delete root->right;
                root->right = right;
            }
    
            if(root->left == nullptr && root->right == nullptr && root->val == 0)
            {
                return nullptr;
            }
            return root;
        }
    };
    